<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="disabled">
      <a-form-model layout="horizontal" ref="subForm" slot="detail" :model="model" :rules="validatorRules" v-bind="formItemLayout">
        <z-form-item :datas="fieldArr" :form="model" :rules="validatorRules" :gutter="0">
        </z-form-item>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { abnormalReportApply } from '@/api/sjsk/personService'
  export default {
    props: {
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model: {},
        confirmLoading: false,
        formItemLayout: {
          labelCol: { span: 6 },
          wrapperCol: { span: 16 }
        },
        fieldArr: [
          {label: '吸毒人员姓名', prop: 'realName', tagType: 'input', disabled: true},
          {label: '性别', prop: 'sex', tagType: 'dict-select', dictCode:'sex', disabled: true},
          {label: '出生日期', prop: 'birthday', tagType: 'date-picker', format: 'YYYY-MM-DD', showTime:false, disabled: true},
          {label: '身份证号', prop: 'identityCard', tagType: 'input', disabled: true},
          {label: '手机号码', prop: 'phone', tagType: 'input', disabled: true},
          {label: '风险类别', prop: 'riskCategory', tagType: 'dict-select', dictCode:'sex', disabled: true},
          {label: '居住地详址', prop: 'currentAddress', tagType: 'input', disabled: true},
          {label: '居住地区', prop: 'currentTown', tagType: 'linkage-area', disabled: true},
          {label: '居住地专干姓名', prop: 'currentManagerName', tagType: 'input', disabled: true},
          {label: '专干联系电话', prop: 'currentManagerPhone', tagType: 'input', disabled: true},
          {label: '居住地民警姓名', prop: 'policeName', tagType: 'input', disabled: true},
          {label: '民警联系电话', prop: 'policePhone', tagType: 'input', disabled: true},
          {label: '户籍地详址', prop: 'householdAddress', tagType: 'input', disabled: true},
          {label: '户籍地区', prop: 'householdTown', tagType: 'linkage-area', disabled: true},
          {label: '当前管控状态', prop: 'currentControlStatus', tagType: 'dict-select', dictCode:'sex', disabled: true},
          {label: '异常上报描述', prop: 'reportDescribe', tagType: 'textarea'},
          {label: '证明材料', prop: 'file', tagType: 'upload-file'},
        ],
        validatorRules: {
          reportDescribe:[ { required: true, message: '请输入异常上报描述!' }]
        }
      }
    },
    methods: {
      show (record) {
        // console.log("222222")
        // console.log(record)
        // this.model = record?Object.assign({}, record):this.model;
        this.$set( this.model, 'controlPersonId', record.controlPersonId )
        this.$set( this.model, 'controlPersonType', 1 ) //管控人员类型 1：社戒社康 2：社会面人员
        this.$set( this.model, 'outsidePersonId', record.id ) //省外异地管控id
        this.$set( this.model, 'realName', record.realName )
        this.$set( this.model, 'birthday', record.birthday )
        this.$set( this.model, 'sex', record.sex )
        this.$set( this.model, 'identityCard', record.identityCard )
        this.$set( this.model, 'phone', record.phone )
        this.$set( this.model, 'householdAddress', record.householdAddress )
        this.$set( this.model, 'riskLevel', record.highRiskSituation )
      },
      submitForm () {
        const parameter = Object.assign({}, this.model)
        this.$refs.subForm.validate((valid)=> {
          if (valid) {
            this.confirmLoading = true
            abnormalReportApply(parameter)
              .then(res => {
                this.confirmLoading = false
                if (res.success) {
                  this.$message.success(res.message)
                  this.$emit('ok');
                } else {
                  this.$message.warn(res.message)
                }
              })
              .catch(e => {
                this.$message.warn('请求失败！')
                this.confirmLoading = false
              })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      }
    }
  }
</script>
